﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyWrite.API.Appicant.Command.Holiday;
using MediatR;

namespace B.S.DataBase.MyWrite.API.Appicant.CommandHandler.Holiday
{
    public class DelHolidayCommandHarder : IRequestHandler<DelHolidayCommand, APIResult<object>>
    {

        private readonly IMapper mapper;
        private readonly IBaseRepository<Holidays> baseRepository;

        public DelHolidayCommandHarder(IMapper mapper, IBaseRepository<Holidays> baseRepository)
        {
            this.mapper = mapper;
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<object>> Handle(DelHolidayCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            var xi = baseRepository.GetAll().Result.Where(x => x.HoId == request.HoId).FirstOrDefault();

            var kk = baseRepository.Delete(xi).Result;
            if (kk > 0)
            {
                result.Code= APIEnum.删除成功;
                result.Msg= APIEnum.删除成功.ToString();
                

            }
            else {
                result.Code = APIEnum.删除失败;
                result.Msg = APIEnum.删除失败.ToString();

            }
            return Task.FromResult(result);
        }
    }
}
